# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=openrct2
pkgver=0.4.4
_pkgver_objects=1.3.10
_pkgver_title_sequences=0.4.0
_pkgver_replays=0.0.78
_pkgver_opensfx=1.0.3
_pkgver_openmsx=1.2.0
pkgrel=3
pkgdesc="Open-source re-implementation of Roller Coaster Tycoon 2"
# s390x is not supported upstream
arch="all !s390x"
url="https://openrct2.io"
license="GPL-3.0-only"
depends="$pkgname-data"
makedepends="
	cmake
	curl-dev
	flac-dev
	fontconfig-dev
	gtest-dev
	icu-dev
	jansson-dev
	libpng-dev
	libvorbis-dev
	libzip-dev
	mesa-dev
	musl-fts-dev
	ninja
	nlohmann-json
	sdl2-dev
	speexdsp-dev
	unzip
	"
install="$pkgname.post-install"
subpackages="$pkgname-doc $pkgname-cli $pkgname-data::noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/openrct2/openrct2/archive/refs/tags/v$pkgver.tar.gz
	$pkgname-$_pkgver_title_sequences-title_sequences.zip::https://github.com/OpenRCT2/title-sequences/releases/download/v$_pkgver_title_sequences/title-sequences.zip
	$pkgname-$_pkgver_objects-objects.zip::https://github.com/OpenRCT2/objects/releases/download/v$_pkgver_objects/objects.zip
	$pkgname-$_pkgver_replays-replays.zip::https://github.com/OpenRCT2/replays/releases/download/v$_pkgver_replays/replays.zip
	$pkgname-$_pkgver_opensfx-opensfx.zip::https://github.com/OpenRCT2/OpenSoundEffects/releases/download/v$_pkgver_opensfx/opensound.zip
	$pkgname-$_pkgver_openmsx-openmsx.zip::https://github.com/OpenRCT2/OpenMusic/releases/download/v$_pkgver_openmsx/openmusic.zip
	Werror.patch
	0001-int32_t.patch
	0004-ftello.patch
	"
# localisation tests fail with new libstdc++ support
#options="!check"
case "$CARCH" in
arm*) options="!check" ;; # https://github.com/OpenRCT2/OpenRCT2/issues/12727
esac
builddir="$srcdir/OpenRCT2-$pkgver"

prepare() {
	default_prepare

	mkdir -p \
		data/title \
		data/object \
		testdata/replays \
		data/assetpack/openrct2.sound.parkap \
		data/assetpack/openrct2.music.alternative.parkap
	unzip "$srcdir"/$pkgname-$_pkgver_title_sequences-title_sequences.zip -d data/title
	unzip "$srcdir"/$pkgname-$_pkgver_objects-objects.zip -d data/object
	unzip "$srcdir"/$pkgname-$_pkgver_replays-replays.zip -d testdata/replays
	unzip "$srcdir"/$pkgname-$_pkgver_opensfx-opensfx.zip -d data/assetpack/openrct2.sound.parkap
	unzip "$srcdir"/$pkgname-$_pkgver_openmsx-openmsx.zip -d data/assetpack/openrct2.music.alternative.parkap
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=ON \
		-DWITH_TESTS=ON \
		-DDOWNLOAD_TITLE_SEQUENCES=OFF \
		-DDOWNLOAD_OBJECTS=OFF \
		-DDOWNLOAD_REPLAYS=OFF \
		-DDOWNLOAD_OPENSFX=OFF \
		-DDOWNLOAD_OPENMSX=OFF \
		-DDISABLE_GOOGLE_BENCHMARK=ON # Not packaged in Alpine
	cmake --build build
}

check() {
	ln -s "$builddir"/data build/data
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest -E "replay_tests|string|localisation|enummaptests"
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

data() {
	amove usr/share/openrct2

	# https://github.com/OpenRCT2/OpenRCT2/issues/12716
	mv "$subpkgdir"/usr/share/openrct2/title \
		"$subpkgdir"/usr/share/openrct2/sequence
}

cli() {
	depends="openrct2-data"
	install="$subpkgname.post-install"

	amove usr/bin/openrct2-cli
}
sha512sums="
8e969e08023a6232dfffa31593cfacedafdf5eb778d1c1471deb095b3d056006ea0c1b219c9042f9fe94118fcbde219580ba2fca29d70a042a016a7fde0abdc9  openrct2-0.4.4.tar.gz
fcfabb02fb7cb9dda7f73f8a24fb426e23b1ea4c417deacd7147e4d2e8942223e0cf9d9cc6ae371f7508e8d3b1f3161e05677a301a330ae265b6610e1c5da487  openrct2-0.4.0-title_sequences.zip
64efe9a147b31e3b88e816558b205b3a1709473ded75193f5838d9bb86c07dfec2bc0e6cd6ec3f9e12327247a015f455bc71024a4645b23d683ea238cb25b14d  openrct2-1.3.10-objects.zip
c6ff18c2206192ed4fb56535732137229f9bced96da00037d691bc64dcdb102cffe37f180054319e7c8ef8dbbd7de49792c3a7e845199fa180612ed97a149b32  openrct2-0.0.78-replays.zip
89784703fb2cda67b5440e06381b44e59ce4a42a88004761c76f0c2b23f78be3692e5fe5e2c8655943e04f7a45e479cfcbc2c3998202222dab16a092b9a73195  openrct2-1.0.3-opensfx.zip
29e3ce57553571b9bf8630520245dbc756f2640318aa4102ec9ff358d7b4507fdb669366d7934620bf50a4445aa9107c52bd93ed6202b565e9e90521638edbb6  openrct2-1.2.0-openmsx.zip
cd39a38a59b8544d38895255e8719a8c1ca404d56073649c2434db5c4aa121d4f86460cb90e04d16d5da61dff95826de9a634d433087c08dcc4f2222208507b1  Werror.patch
c56151de6ec2f4b9ca279ef038e3c3be87f1a61d6d6ebb1abbddc0aabbd5913aaa88fa724663cd2e2cd3729868b61e727c3dcfd03af5685ed6ca583e16ee0cb3  0001-int32_t.patch
98b7f0d0fda5a25aaec21e31a65e15cf9cff647af66e1e619afb43d01662d050390f936435e761d8eacdf1c44cd12b7c69009af9791fc77436af41e43ba75b32  0004-ftello.patch
"
